<article class="" id="post-">
<header class="entry-header">
<h1 class="entry-title">.queue()</h1>
<div class="entry-meta">
						所属分类：<span class="category"><a href="/category/effects/">特效</a> &gt; <a href="/category/effects/custom-effects/">自定义</a></span><span class="category-divider"> | </span><span class="category"><a href="/category/data/">数据操作</a></span><span class="category-divider"> | </span><span class="category"><a href="/category/utilities/">工具类</a></span>
<span class="pull-right">英文文档：<a href="https://api.jquery123.com/queue/" target="_blank">.queue()</a></span>
</div><!-- .entry-meta -->
</header><!-- .entry-header -->
<!-- .entry-header -->
<div class="entry-content">显示或操作匹配的元素上已经执行的函数列队。<div class="toc">
<h4><span>Contents:</span></h4>
<ul class="toc-list">
<li>
<a href="#queue1">.queue(  [queueName ] )</a><ul><li>.queue(  [queueName ] )</li></ul>
</li>
<li>
<a href="#queue2">.queue(  [queueName ], newQueue )</a><ul>
<li>.queue(  [queueName ], newQueue )</li>
<li>.queue(  [queueName ], callback( next ) )</li>
</ul>
</li>
</ul>
</div><article class="entry method" id="queue1"><h2 class="section-title">
<span class="name">.queue(  [queueName ] )</span><span class="returns">返回: <a href="/Types/#Array">Array</a></span>
</h2>
<div class="entry-wrapper">
<p class="desc"><strong>描述: </strong>显示在匹配的元素上的已经执行的函数列队。</p>
<ul class="signatures"><li class="signature" id="queue-queueName">
<h4 class="name">
<span class="version-details">添加的版本: <a href="/category/version/1.2/">1.2</a></span>.queue(  [queueName ] )</h4>
<ul><li>
<div><strong>queueName</strong></div>
<div>类型: <a href="/Types/#String">String</a>
</div>
<div>一个含有队列名的字符串。默认是 <code>fx</code>，标准的动画队列。</div>
</li></ul>
</li></ul>
<section class="entry-examples" id="entry-examples"><header><h2 class="underline">例子:</h2></header><div class="entry-example" id="example-0">
<h4><span class="desc">显示列队的长度。</span></h4>
<div class="syntaxhighlighter xml ">
<table>
<tbody>
<tr>
<td class="gutter">
<div class="line n1">1</div>
<div class="line n2">2</div>
<div class="line n3">3</div>
<div class="line n4">4</div>
<div class="line n5">5</div>
<div class="line n6">6</div>
<div class="line n7">7</div>
<div class="line n8">8</div>
<div class="line n9">9</div>
<div class="line n10">10</div>
<div class="line n11">11</div>
<div class="line n12">12</div>
<div class="line n13">13</div>
<div class="line n14">14</div>
<div class="line n15">15</div>
<div class="line n16">16</div>
<div class="line n17">17</div>
<div class="line n18">18</div>
<div class="line n19">19</div>
<div class="line n20">20</div>
<div class="line n21">21</div>
<div class="line n22">22</div>
<div class="line n23">23</div>
<div class="line n24">24</div>
<div class="line n25">25</div>
<div class="line n26">26</div>
<div class="line n27">27</div>
<div class="line n28">28</div>
<div class="line n29">29</div>
<div class="line n30">30</div>
<div class="line n31">31</div>
<div class="line n32">32</div>
<div class="line n33">33</div>
<div class="line n34">34</div>
<div class="line n35">35</div>
<div class="line n36">36</div>
<div class="line n37">37</div>
<div class="line n38">38</div>
<div class="line n39">39</div>
<div class="line n40">40</div>
</td>
<td class="code">
<pre><div class="container"><div class="line"><code><span class="doctype">&lt;!DOCTYPE html&gt;</span></code></div></div><div class="container"><div class="line"><code><span class="tag">&lt;<span class="title">html</span>&gt;</span></code></div></div><div class="container"><div class="line"><code><span class="tag">&lt;<span class="title">head</span>&gt;</span></code></div></div><div class="container"><div class="line"><code>  <span class="tag">&lt;<span class="title">style</span>&gt;</span><span class="css"><span class="tag">div</span> <span class="rules">{ <span class="rule"><span class="attribute">margin</span>:<span class="value"><span class="number">3</span>px;</span></span> <span class="rule"><span class="attribute">width</span>:<span class="value"><span class="number">40</span>px;</span></span> <span class="rule"><span class="attribute">height</span>:<span class="value"><span class="number">40</span>px;</span></span></span></span></code></div></div><div class="container"><div class="line"><code>        <span class="rule"><span class="attribute">position</span>:<span class="value">absolute;</span></span> <span class="rule"><span class="attribute">left</span>:<span class="value"><span class="number">0</span>px;</span></span> <span class="rule"><span class="attribute">top</span>:<span class="value"><span class="number">60</span>px;</span></span></code></div></div><div class="container"><div class="line"><code>        <span class="rule"><span class="attribute">background</span>:<span class="value">green;</span></span> <span class="rule"><span class="attribute">display</span>:<span class="value">none;</span></span> <span class="rule">}</span></code></div></div><div class="container"><div class="line"><code>  <span class="tag">div</span><span class="class">.newcolor</span> <span class="rules">{ <span class="rule"><span class="attribute">background</span>:<span class="value">blue;</span></span> <span class="rule">}</span></span></code></div></div><div class="container"><div class="line"><code>  <span class="tag">p</span> <span class="rules">{ <span class="rule"><span class="attribute">color</span>:<span class="value">red;</span></span> <span class="rule">}</span></span>  <span class="tag">&lt;/<span class="title">style</span>&gt;</span></code></div></div><div class="container"><div class="line"><code>  <span class="tag">&lt;<span class="title">script</span> <span class="attribute">src</span>=<span class="value">"https://code.jquery.com/jquery-latest.js"</span>&gt;</span><span class="javascript"></span><span class="tag">&lt;/<span class="title">script</span>&gt;</span></code></div></div><div class="container"><div class="line"><code><span class="tag">&lt;/<span class="title">head</span>&gt;</span></code></div></div><div class="container"><div class="line"><code><span class="tag">&lt;<span class="title">body</span>&gt;</span></code></div></div><div class="container"><div class="line"><code> </code></div></div><div class="container"><div class="line"><code>  <span class="tag">&lt;<span class="title">p</span>&gt;</span>The queue length is: <span class="tag">&lt;<span class="title">span</span>&gt;</span><span class="tag">&lt;/<span class="title">span</span>&gt;</span><span class="tag">&lt;/<span class="title">p</span>&gt;</span></code></div></div><div class="container"><div class="line"><code>  <span class="tag">&lt;<span class="title">div</span>&gt;</span><span class="tag">&lt;/<span class="title">div</span>&gt;</span></code></div></div><div class="container"><div class="line"><code><span class="tag">&lt;<span class="title">script</span>&gt;</span><span class="javascript"></span></code></div></div><div class="container"><div class="line"><code><span class="keyword">var</span> div = $(<span class="string">"div"</span>);</code></div></div><div class="container"><div class="line"><code> </code></div></div><div class="container"><div class="line"><code><span class="function"><span class="keyword">function</span> <span class="title">runIt</span><span class="params">()</span> {</span></code></div></div><div class="container"><div class="line"><code>  div.show(<span class="string">"slow"</span>);</code></div></div><div class="container"><div class="line"><code>  div.animate({left:<span class="string">'+=200'</span>},<span class="number">2000</span>);</code></div></div><div class="container"><div class="line"><code>  div.slideToggle(<span class="number">1000</span>);</code></div></div><div class="container"><div class="line"><code>  div.slideToggle(<span class="string">"fast"</span>);</code></div></div><div class="container"><div class="line"><code>  div.animate({left:<span class="string">'-=200'</span>},<span class="number">1500</span>);</code></div></div><div class="container"><div class="line"><code>  div.hide(<span class="string">"slow"</span>);</code></div></div><div class="container"><div class="line"><code>  div.show(<span class="number">1200</span>);</code></div></div><div class="container"><div class="line"><code>  div.slideUp(<span class="string">"normal"</span>, runIt);</code></div></div><div class="container"><div class="line"><code>}</code></div></div><div class="container"><div class="line"><code> </code></div></div><div class="container"><div class="line"><code><span class="function"><span class="keyword">function</span> <span class="title">showIt</span><span class="params">()</span> {</span></code></div></div><div class="container"><div class="line"><code>  <span class="keyword">var</span> n = div.queue(<span class="string">"fx"</span>);</code></div></div><div class="container"><div class="line"><code>  $(<span class="string">"span"</span>).text( n.length );</code></div></div><div class="container"><div class="line"><code>  setTimeout(showIt, <span class="number">100</span>);</code></div></div><div class="container"><div class="line"><code>}</code></div></div><div class="container"><div class="line"><code> </code></div></div><div class="container"><div class="line"><code>runIt();</code></div></div><div class="container"><div class="line"><code>showIt();</code></div></div><div class="container"><div class="line"><code><span class="tag">&lt;/<span class="title">script</span>&gt;</span></code></div></div><div class="container"><div class="line"><code> </code></div></div><div class="container"><div class="line"><code><span class="tag">&lt;/<span class="title">body</span>&gt;</span></code></div></div><div class="container"><div class="line"><code><span class="tag">&lt;/<span class="title">html</span>&gt;</span></code></div></div></pre>
</td>
</tr>
</tbody>
</table>
</div>
<h4>Demo:</h4>
<div class="demo code-demo"></div>
</div></section>
</div></article><article class="entry method" id="queue2"><h2 class="section-title">
<span class="name">.queue(  [queueName ], newQueue )</span><span class="returns">返回: <a href="/Types/#jQuery">jQuery</a></span>
</h2>
<div class="entry-wrapper">
<p class="desc"><strong>描述: </strong>在匹配元素上操作已经附加函数的列表。</p>
<ul class="signatures">
<li class="signature" id="queue-queueName-newQueue">
<h4 class="name">
<span class="version-details">添加的版本: <a href="/category/version/1.2/">1.2</a></span>.queue(  [queueName ], newQueue )</h4>
<ul>
<li>
<div><strong>queueName</strong></div>
<div>类型: <a href="/Types/#String">String</a>
</div>
<div>一个含有队列名的字符串。默认是 <code>fx</code>，标准的动画队列。</div>
</li>
<li>
<div><strong>newQueue</strong></div>
<div>类型: <a href="/Types/#Array">Array</a>
</div>
<div>一个替换当前列队内容的函数数组。</div>
</li>
</ul>
</li>
<li class="signature" id="queue-queueName-callback-next-">
<h4 class="name">
<span class="version-details">添加的版本: <a href="/category/version/1.2/">1.2</a></span>.queue(  [queueName ], callback( next ) )</h4>
<ul>
<li>
<div><strong>queueName</strong></div>
<div>类型: <a href="/Types/#String">String</a>
</div>
<div>一个含有队列名的字符串。默认是 <code>fx</code>，标准的动画队列。</div>
</li>
<li>
<div><strong>callback( next )</strong></div>
<div>类型: <a href="/Types/#Function">Function</a>()</div>
<div>将要添加到队列中的新函数。当该函数被调用时，会从弹出队列中的下一个元素。</div>
</li>
</ul>
</li>
</ul>
<div class="longdesc" id="entry-longdesc-1">
<p>每个元素可以通过jQuery，包含一个或多个函数队列。在大多数应用中，只有一个列队(访问 <code>fx</code>)被使用。队列允许一个元素来异步的访问一连串的动作，而不终止程序执行。典型的例子就是在一个元素上调用多重动画的方法对一个元素。例如：</p>
<div class="syntaxhighlighter javascript nogutter">
<table>
<tbody>
<tr>
<td class="gutter">
<div class="line n1">1</div>
</td>
<td class="code">
<pre><div class="container"><div class="line"><code>$(<span class="string">'#foo'</span>).slideUp().fadeIn();</code></div></div></pre>
</td>
</tr>
</tbody>
</table>
</div>
<p>当这个语句被执行，这个元素开始立即做滑动动画，但渐入动画放置在 <code>fx</code> 列队在，只有当滑动动画完成后才会被执行。</p>
<p><code>queue()</code>方法允许我们直接操纵这个函数队列。用一个回调函数访问<code>queue()</code>特别的有用；它让我们把新函数置入到队列的末端。为jQuery集合中的每个元素执行一次回调函数。</p>
<p>该函数的功能类似于在动画方法中提供了回调函数，但是不要求在动画执行时指定回调函数。</p>
<div class="syntaxhighlighter javascript nogutter">
<table>
<tbody>
<tr>
<td class="gutter">
<div class="line n1">1</div>
<div class="line n2">2</div>
<div class="line n3">3</div>
<div class="line n4">4</div>
<div class="line n5">5</div>
</td>
<td class="code">
<pre><div class="container"><div class="line"><code>$(<span class="string">'#foo'</span>).slideUp();</code></div></div><div class="container"><div class="line"><code>$(<span class="string">'#foo'</span>).queue(<span class="keyword">function</span>() {</code></div></div><div class="container"><div class="line"><code>  alert(<span class="string">'Animation complete.'</span>);</code></div></div><div class="container"><div class="line"><code>  $(<span class="keyword">this</span>).dequeue();</code></div></div><div class="container"><div class="line"><code>});</code></div></div></pre>
</td>
</tr>
</tbody>
</table>
</div>
<p>这是相当于：</p>
<div class="syntaxhighlighter javascript nogutter">
<table>
<tbody>
<tr>
<td class="gutter">
<div class="line n1">1</div>
<div class="line n2">2</div>
<div class="line n3">3</div>
</td>
<td class="code">
<pre><div class="container"><div class="line"><code>$(<span class="string">'#foo'</span>).slideUp(<span class="keyword">function</span>() {</code></div></div><div class="container"><div class="line"><code>  alert(<span class="string">'Animation complete.'</span>);</code></div></div><div class="container"><div class="line"><code>});</code></div></div></pre>
</td>
</tr>
</tbody>
</table>
</div>
<p>值得注意的是，当使用<code>.queue()</code>添加一个函数的时候，我们应该保证在函数最后调用了 <code>jQuery.dequeue()</code>，这样就能让队列中的其它函数按顺序执行。</p>
<p><strong>从jQuery 1.4开始</strong>，向队列中追加函数时，可以向该函数中传入另一个函数，作为第一个参数。当调用函数时，会自动从函数队列中弹出下一个项目，保证队列中函数的继续进行。我们可以像下面这样使用：</p>
<div class="syntaxhighlighter javascript nogutter">
<table>
<tbody>
<tr>
<td class="gutter">
<div class="line n1">1</div>
<div class="line n2">2</div>
<div class="line n3">3</div>
<div class="line n4">4</div>
</td>
<td class="code">
<pre><div class="container"><div class="line"><code>$(<span class="string">"#test"</span>).queue(<span class="keyword">function</span>(next) {</code></div></div><div class="container"><div class="line"><code>    <span class="comment">// Do some stuff...</span></code></div></div><div class="container"><div class="line"><code>    next();</code></div></div><div class="container"><div class="line"><code>});</code></div></div></pre>
</td>
</tr>
</tbody>
</table>
</div>
</div>
<section class="entry-examples" id="entry-examples-1"><header><h2 class="underline">例子:</h2></header><div class="entry-example" id="example-1-0">
<h4>Example: <span class="desc">Queue a custom function.</span>
</h4>
<div class="syntaxhighlighter xml ">
<table>
<tbody>
<tr>
<td class="gutter">
<div class="line n1">1</div>
<div class="line n2">2</div>
<div class="line n3">3</div>
<div class="line n4">4</div>
<div class="line n5">5</div>
<div class="line n6">6</div>
<div class="line n7">7</div>
<div class="line n8">8</div>
<div class="line n9">9</div>
<div class="line n10">10</div>
<div class="line n11">11</div>
<div class="line n12">12</div>
<div class="line n13">13</div>
<div class="line n14">14</div>
<div class="line n15">15</div>
<div class="line n16">16</div>
<div class="line n17">17</div>
<div class="line n18">18</div>
<div class="line n19">19</div>
<div class="line n20">20</div>
<div class="line n21">21</div>
<div class="line n22">22</div>
<div class="line n23">23</div>
<div class="line n24">24</div>
<div class="line n25">25</div>
<div class="line n26">26</div>
<div class="line n27">27</div>
<div class="line n28">28</div>
<div class="line n29">29</div>
<div class="line n30">30</div>
<div class="line n31">31</div>
</td>
<td class="code">
<pre><div class="container"><div class="line"><code><span class="doctype">&lt;!DOCTYPE html&gt;</span></code></div></div><div class="container"><div class="line"><code><span class="tag">&lt;<span class="title">html</span>&gt;</span></code></div></div><div class="container"><div class="line"><code><span class="tag">&lt;<span class="title">head</span>&gt;</span></code></div></div><div class="container"><div class="line"><code>  <span class="tag">&lt;<span class="title">style</span>&gt;</span><span class="css"></span></code></div></div><div class="container"><div class="line"><code>  <span class="tag">div</span> <span class="rules">{ <span class="rule"><span class="attribute">margin</span>:<span class="value"><span class="number">3</span>px;</span></span> <span class="rule"><span class="attribute">width</span>:<span class="value"><span class="number">40</span>px;</span></span> <span class="rule"><span class="attribute">height</span>:<span class="value"><span class="number">40</span>px;</span></span></span></code></div></div><div class="container"><div class="line"><code>        <span class="rule"><span class="attribute">position</span>:<span class="value">absolute;</span></span> <span class="rule"><span class="attribute">left</span>:<span class="value"><span class="number">0</span>px;</span></span> <span class="rule"><span class="attribute">top</span>:<span class="value"><span class="number">30</span>px;</span></span></code></div></div><div class="container"><div class="line"><code>        <span class="rule"><span class="attribute">background</span>:<span class="value">green;</span></span> <span class="rule"><span class="attribute">display</span>:<span class="value">none;</span></span> <span class="rule">}</span></code></div></div><div class="container"><div class="line"><code>  <span class="tag">div</span><span class="class">.newcolor</span> <span class="rules">{ <span class="rule"><span class="attribute">background</span>:<span class="value">blue;</span></span> <span class="rule">}</span></span></code></div></div><div class="container"><div class="line"><code>  <span class="tag">&lt;/<span class="title">style</span>&gt;</span></code></div></div><div class="container"><div class="line"><code>  <span class="tag">&lt;<span class="title">script</span> <span class="attribute">src</span>=<span class="value">"https://code.jquery.com/jquery-latest.js"</span>&gt;</span><span class="javascript"></span><span class="tag">&lt;/<span class="title">script</span>&gt;</span></code></div></div><div class="container"><div class="line"><code><span class="tag">&lt;/<span class="title">head</span>&gt;</span></code></div></div><div class="container"><div class="line"><code><span class="tag">&lt;<span class="title">body</span>&gt;</span></code></div></div><div class="container"><div class="line"><code>  Click here...</code></div></div><div class="container"><div class="line"><code>  <span class="tag">&lt;<span class="title">div</span>&gt;</span><span class="tag">&lt;/<span class="title">div</span>&gt;</span></code></div></div><div class="container"><div class="line"><code><span class="tag">&lt;<span class="title">script</span>&gt;</span><span class="javascript">$(document.body).click(<span class="function"><span class="keyword">function</span> <span class="params">()</span> {</span></span></code></div></div><div class="container"><div class="line"><code>      $(<span class="string">"div"</span>).show(<span class="string">"slow"</span>);</code></div></div><div class="container"><div class="line"><code>      $(<span class="string">"div"</span>).animate({left:<span class="string">'+=200'</span>},<span class="number">2000</span>);</code></div></div><div class="container"><div class="line"><code>      $(<span class="string">"div"</span>).queue(<span class="function"><span class="keyword">function</span> <span class="params">()</span> {</span></code></div></div><div class="container"><div class="line"><code>        $(<span class="keyword">this</span>).addClass(<span class="string">"newcolor"</span>);</code></div></div><div class="container"><div class="line"><code>        $(<span class="keyword">this</span>).dequeue();</code></div></div><div class="container"><div class="line"><code>      });</code></div></div><div class="container"><div class="line"><code>      $(<span class="string">"div"</span>).animate({left:<span class="string">'-=200'</span>},<span class="number">500</span>);</code></div></div><div class="container"><div class="line"><code>      $(<span class="string">"div"</span>).queue(<span class="function"><span class="keyword">function</span> <span class="params">()</span> {</span></code></div></div><div class="container"><div class="line"><code>        $(<span class="keyword">this</span>).removeClass(<span class="string">"newcolor"</span>);</code></div></div><div class="container"><div class="line"><code>        $(<span class="keyword">this</span>).dequeue();</code></div></div><div class="container"><div class="line"><code>      });</code></div></div><div class="container"><div class="line"><code>      $(<span class="string">"div"</span>).slideUp();</code></div></div><div class="container"><div class="line"><code>    });<span class="tag">&lt;/<span class="title">script</span>&gt;</span></code></div></div><div class="container"><div class="line"><code> </code></div></div><div class="container"><div class="line"><code><span class="tag">&lt;/<span class="title">body</span>&gt;</span></code></div></div><div class="container"><div class="line"><code><span class="tag">&lt;/<span class="title">html</span>&gt;</span></code></div></div></pre>
</td>
</tr>
</tbody>
</table>
</div>
<h4>Demo:</h4>
<div class="demo code-demo"></div>
</div>
<div class="entry-example" id="example-1-1">
<h4>Example: <span class="desc">Set a queue array to delete the queue.</span>
</h4>
<div class="syntaxhighlighter xml ">
<table>
<tbody>
<tr>
<td class="gutter">
<div class="line n1">1</div>
<div class="line n2">2</div>
<div class="line n3">3</div>
<div class="line n4">4</div>
<div class="line n5">5</div>
<div class="line n6">6</div>
<div class="line n7">7</div>
<div class="line n8">8</div>
<div class="line n9">9</div>
<div class="line n10">10</div>
<div class="line n11">11</div>
<div class="line n12">12</div>
<div class="line n13">13</div>
<div class="line n14">14</div>
<div class="line n15">15</div>
<div class="line n16">16</div>
<div class="line n17">17</div>
<div class="line n18">18</div>
<div class="line n19">19</div>
<div class="line n20">20</div>
<div class="line n21">21</div>
<div class="line n22">22</div>
<div class="line n23">23</div>
<div class="line n24">24</div>
<div class="line n25">25</div>
<div class="line n26">26</div>
<div class="line n27">27</div>
<div class="line n28">28</div>
<div class="line n29">29</div>
<div class="line n30">30</div>
<div class="line n31">31</div>
<div class="line n32">32</div>
<div class="line n33">33</div>
<div class="line n34">34</div>
<div class="line n35">35</div>
<div class="line n36">36</div>
</td>
<td class="code">
<pre><div class="container"><div class="line"><code><span class="doctype">&lt;!DOCTYPE html&gt;</span></code></div></div><div class="container"><div class="line"><code><span class="tag">&lt;<span class="title">html</span>&gt;</span></code></div></div><div class="container"><div class="line"><code><span class="tag">&lt;<span class="title">head</span>&gt;</span></code></div></div><div class="container"><div class="line"><code>  <span class="tag">&lt;<span class="title">style</span>&gt;</span><span class="css"></span></code></div></div><div class="container"><div class="line"><code>  <span class="tag">div</span> <span class="rules">{ <span class="rule"><span class="attribute">margin</span>:<span class="value"><span class="number">3</span>px;</span></span> <span class="rule"><span class="attribute">width</span>:<span class="value"><span class="number">40</span>px;</span></span> <span class="rule"><span class="attribute">height</span>:<span class="value"><span class="number">40</span>px;</span></span></span></code></div></div><div class="container"><div class="line"><code>        <span class="rule"><span class="attribute">position</span>:<span class="value">absolute;</span></span> <span class="rule"><span class="attribute">left</span>:<span class="value"><span class="number">0</span>px;</span></span> <span class="rule"><span class="attribute">top</span>:<span class="value"><span class="number">30</span>px;</span></span></code></div></div><div class="container"><div class="line"><code>        <span class="rule"><span class="attribute">background</span>:<span class="value">green;</span></span> <span class="rule"><span class="attribute">display</span>:<span class="value">none;</span></span> <span class="rule">}</span></code></div></div><div class="container"><div class="line"><code>  <span class="tag">div</span><span class="class">.newcolor</span> <span class="rules">{ <span class="rule"><span class="attribute">background</span>:<span class="value">blue;</span></span> <span class="rule">}</span></span></code></div></div><div class="container"><div class="line"><code>  <span class="tag">&lt;/<span class="title">style</span>&gt;</span></code></div></div><div class="container"><div class="line"><code>  <span class="tag">&lt;<span class="title">script</span> <span class="attribute">src</span>=<span class="value">"https://code.jquery.com/jquery-latest.js"</span>&gt;</span><span class="javascript"></span><span class="tag">&lt;/<span class="title">script</span>&gt;</span></code></div></div><div class="container"><div class="line"><code><span class="tag">&lt;/<span class="title">head</span>&gt;</span></code></div></div><div class="container"><div class="line"><code><span class="tag">&lt;<span class="title">body</span>&gt;</span></code></div></div><div class="container"><div class="line"><code>  <span class="tag">&lt;<span class="title">button</span> <span class="attribute">id</span>=<span class="value">"start"</span>&gt;</span>Start<span class="tag">&lt;/<span class="title">button</span>&gt;</span></code></div></div><div class="container"><div class="line"><code>  <span class="tag">&lt;<span class="title">button</span> <span class="attribute">id</span>=<span class="value">"stop"</span>&gt;</span>Stop<span class="tag">&lt;/<span class="title">button</span>&gt;</span></code></div></div><div class="container"><div class="line"><code>  <span class="tag">&lt;<span class="title">div</span>&gt;</span><span class="tag">&lt;/<span class="title">div</span>&gt;</span></code></div></div><div class="container"><div class="line"><code><span class="tag">&lt;<span class="title">script</span>&gt;</span><span class="javascript">$(<span class="string">"#start"</span>).click(<span class="function"><span class="keyword">function</span> <span class="params">()</span> {</span></span></code></div></div><div class="container"><div class="line"><code>      $(<span class="string">"div"</span>).show(<span class="string">"slow"</span>);</code></div></div><div class="container"><div class="line"><code>      $(<span class="string">"div"</span>).animate({left:<span class="string">'+=200'</span>},<span class="number">5000</span>);</code></div></div><div class="container"><div class="line"><code>      $(<span class="string">"div"</span>).queue(<span class="function"><span class="keyword">function</span> <span class="params">()</span> {</span></code></div></div><div class="container"><div class="line"><code>        $(<span class="keyword">this</span>).addClass(<span class="string">"newcolor"</span>);</code></div></div><div class="container"><div class="line"><code>        $(<span class="keyword">this</span>).dequeue();</code></div></div><div class="container"><div class="line"><code>      });</code></div></div><div class="container"><div class="line"><code>      $(<span class="string">"div"</span>).animate({left:<span class="string">'-=200'</span>},<span class="number">1500</span>);</code></div></div><div class="container"><div class="line"><code>      $(<span class="string">"div"</span>).queue(<span class="function"><span class="keyword">function</span> <span class="params">()</span> {</span></code></div></div><div class="container"><div class="line"><code>        $(<span class="keyword">this</span>).removeClass(<span class="string">"newcolor"</span>);</code></div></div><div class="container"><div class="line"><code>        $(<span class="keyword">this</span>).dequeue();</code></div></div><div class="container"><div class="line"><code>      });</code></div></div><div class="container"><div class="line"><code>      $(<span class="string">"div"</span>).slideUp();</code></div></div><div class="container"><div class="line"><code>    });</code></div></div><div class="container"><div class="line"><code>    $(<span class="string">"#stop"</span>).click(<span class="function"><span class="keyword">function</span> <span class="params">()</span> {</span></code></div></div><div class="container"><div class="line"><code>      $(<span class="string">"div"</span>).queue(<span class="string">"fx"</span>, []);</code></div></div><div class="container"><div class="line"><code>      $(<span class="string">"div"</span>).stop();</code></div></div><div class="container"><div class="line"><code>    });<span class="tag">&lt;/<span class="title">script</span>&gt;</span></code></div></div><div class="container"><div class="line"><code> </code></div></div><div class="container"><div class="line"><code><span class="tag">&lt;/<span class="title">body</span>&gt;</span></code></div></div><div class="container"><div class="line"><code><span class="tag">&lt;/<span class="title">html</span>&gt;</span></code></div></div></pre>
</td>
</tr>
</tbody>
</table>
</div>
<h4>Demo:</h4>
<div class="demo code-demo"></div>
</div></section>
</div></article> </div>
</article>